/*
 * Copyright 2012-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.support.SpringFactoriesLoader;

/**
 * Listener for the {@link SpringApplication} {@code run} method.
 * {@link SpringApplicationRunListener}s are loaded via the {@link SpringFactoriesLoader}
 * and should declare a public constructor that accepts a {@link SpringApplication}
 * instance and a {@code String[]} of arguments. A new
 * {@link SpringApplicationRunListener} instance will be created for each run.
 *
 * @author Phillip Webb
 * @author Dave Syer
 * @author Andy Wilkinson
 * @since 1.0.0
 */
public interface SpringApplicationRunListener {


	/**
	 *
	 * 当run方法第一次启动时立即调用。可以用于非常早期的初始化。
	 */
	void starting();
	/**
	 * 在准备环境之后，但在创建ApplicationContext之前调用。
	 */
	void environmentPrepared(ConfigurableEnvironment environment);
	/**
	 * 一旦创建并准备好了ApplicationContext，但是在加载源之前调用。
	 */
	void contextPrepared(ConfigurableApplicationContext context);
	/**
	 * 在加载应用程序上下文之前调用
	 * @param context the application context
	 */
	void contextLoaded(ConfigurableApplicationContext context);
	/**
	 * 上下文已经刷新并且应用程序已经启动，但是ApplicationRunner还没有通知去执行的，
	 * @since 2.0.0
	 */
	void started(ConfigurableApplicationContext context);
	/**
	 * 当应用程序上下文被刷新并且所有
	 * {@link ApplicationRunner ApplicationRunners}和{@link ApplicationRunner ApplicationRunners}
	 * 都被调用时，在run方法结束之前立即调用。
	 * @param context the application context.
	 * @since 2.0.0
	 */
	void running(ConfigurableApplicationContext context);
	/**
	 * 在运行应用程序时发生故障时调用。
	 *
	 * @param context the application context or {@code null} if a failure occurred before
	 * the context was created
	 * @param exception the failure
	 * @since 2.0.0
	 */
	void failed(ConfigurableApplicationContext context, Throwable exception);

}
